import type { App } from 'vue'
import { auth } from '@/utils/auth'

export function directives(app: App) {
  // 鉴权指令
  authDirective(app)
}

/**
 * 页面按钮鉴权指令
 * @description v-auth="'name'"，name可以为：index,add,edit,del,...
 */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function authDirective(app: App) {
  app.directive('auth', {
    mounted(el, binding) {
      if (!binding.value) return false
      if (!auth(binding.value)) el.parentNode.removeChild(el)
    }
  })
}
